package com.boot.security.server.dao;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import com.baomidou.dynamic.datasource.annotation.DS;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.boot.security.server.model.SysUser;

@Mapper
public interface UserDao {

	@Options(useGeneratedKeys = true, keyProperty = "id")
	@Insert("insert into sys_user(username, password, nickname, headImgUrl, phone, telephone, email, birthday, sex, status, createTime, updateTime,openid,hostcode,flag) values(#{username}, #{password}, #{nickname}, #{headImgUrl}, #{phone}, #{telephone}, #{email}, #{birthday}, #{sex}, #{status}, now(), now(),#{openid},#{hostcode},#{flag})")
	int save(SysUser user);

	@Select("select * from sys_user t where t.id = #{id}")
	SysUser getById(Long id);


	@Select("select * from sys_user t where t.username = #{username}")
	SysUser getByuser(String username);
	@Select("select * from sys_user t where t.openid = #{openid}")
	SysUser getByopenid(String openid);

	@Select("select * from sys_user t where t.username = #{username}")
	SysUser getUser(String username);

	@Update("update sys_user t set t.password = #{password} where t.id = #{id}")
	int changePassword(@Param("id") Long id, @Param("password") String password);

	Integer count(@Param("params") Map<String, Object> params);

	List<SysUser> list(@Param("params") Map<String, Object> params, @Param("offset") Integer offset,
			@Param("limit") Integer limit);

	@Delete("delete from sys_role_user where userId = #{userId}")
	int deleteUserRole(Long userId);
	@DS("hitapp")
	@Select("select top 10 * from xt_user t")
	 List<Map<Long, Map<String,Object>>>  getmap(String username);

	@DS("hitapp")
	List getNamesByIds();
	int saveUserRoles(@Param("userId") Long userId, @Param("roleIds") List<Long> roleIds);

	int update(SysUser user);

	@DS("hitapp")
	List test(@Param("hos_code") String hos_code, @Param("dept_code2") String dept_code2, @Param("dept_code1") String dept_code1,
		 @Param("doctor_code") String doctor_code, @Param("begin_date")  String begin_date,
		 @Param("end_date") String end_date);




}
